package util;

import org.junit.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @author raok
 * @create 2022-04-27-22:53
 **/
public class PropertyUtil {
    /**
     * 获取 data.properties,即基础数据配置的数据
     * @param key
     * @return
     */
    public static String getPropertiesValue(String key){
        Properties properties = new Properties();
        String str="";
        try {
//            InputStreamReader  fileInputStream = new InputStreamReader(Properties.class.getClassLoader().getResourceAsStream("src/main/resources/baseData.properties"),"utf-8");
            InputStream fileInputStream = new FileInputStream(new File("src/main/resources/baseData2.properties"));
            properties.load(fileInputStream);
            str = new String(properties.getProperty(key).getBytes(StandardCharsets.ISO_8859_1),"utf-8"); //解决中文乱码
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
    @Test
    public void test(){
        System.out.println(PropertyUtil.getPropertiesValue("majorNames"));
    }
}
